<?php
/**
 * RadioEveningController.class.php
 * 晚间电台控制器
 * 
 * @author 	王中艺	<wangzy_smile@qq.com>
 * @date 	2017-05-04
 */

namespace Wechat\Controller;

class RadioEveningController extends BaseController {

	function index(){
		$userInfo 	= C('User');

		//自动执行签到
		D('Check')->checkToday($userInfo['id']);

		//弹窗展示
		$modalShow 	= date('w') == 1 && !S('modal_show_'.$userInfo['id']) ? 1 : 0;
		if($modalShow){
			S('modal_show_'.$userInfo['id'], 1, 3600 * 24);
		}

		//签到信息获取
		$checkInfo 	= D('Check')->getLastInfo($userInfo['id']);
		$checkInfo['format_keep_days']	= sprintf('%03d', $checkInfo['keep_days']);

		//获取电台故事列表
		$storyList 	= $userInfo['vip_level'] > 0 && $userInfo['vip_level'] != 10 ?
			D('RadioStory')->getList(['status' => 1], 1) : [];

		$this->response([
			'radio_info'	=> D('RadioEvening')->getNewItem(),
			'story_list'	=> $storyList,
			'user_info'	=> $userInfo,
			'listen_count'	=> get_online_count(),
			'check_info'	=> $checkInfo,
			'modal_show'	=> $modalShow,
			'parent_will'	=> D('PlatInfo')->getItem('EVENING_PARENT_WILL')
		]);
	}

	/**
	 * 获取电台故事列表
	 * @param 	$p
	 * @return 	$list
	 */
	function getStoryList(){
		$page 	= $this->iInfo['p'];
		$list 	= D('RadioStory')->getList(['status' => 1], $page);
		$this->outOInfo(['list' => $list]);
	}

	/**
	 * 记录动作
	 * @param 	$target_type 	目标类型
	 * @param 	$radio_id	电台ID
	 * @return 	boolean
	 */
	function logAction(){
		$this->unEmptyParam(['target_type', 'radio_id']);
		if($this->iInfo['target_type'] == 'radio_evening'){
			$relateType 	= 4;
		}else{
			$relateType 	= 5;
		}

		$relateId 	= $this->iInfo['radio_id'];
		$userId 	= C('user.id');

		D('Action')->addItem($userId, $relateType, $relateId);

		$this->outOInfo('Oh yes!');
	}
}